package prepared;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class demo2 {
    public static void main(String[] args) throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/yzy_db";
        String username = "root";
        String pwd = "123456";
        Connection con = DriverManager.getConnection(url, username, pwd);
        String sql = "update t_yzy set name=?,age=? where id=?";
        PreparedStatement pst = con.prepareStatement(sql);
        pst.setString(1, "小小");
        pst.setInt(2, 1);
        pst.setInt(3, 2);
        int count = pst.executeUpdate();
        if (count > 0) {
            System.out.println("修改成功");
        } else {
            System.out.println("修改失败");
        }
        pst.close();
        con.close();
    }
}

